import { useEffect } from "react";
import type { RefObject } from "react";
type useSizeType = (chart: RefObject<Highcharts.Chart | null>) => void;

const useSize: useSizeType = chartRef => {
  // 处理窗口大小变化
  useEffect(() => {
    const handleResize = () => {
      if (chartRef.current) {
        chartRef.current.reflow();
      }
    };

    window.addEventListener("resize", handleResize);

    return () => {
      window.removeEventListener("resize", handleResize);
    };
  }, []);
  return null;
};

export default useSize;
